﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using XToolkit.Text;

namespace Xwork.SEO
{
    public class DbInitializer : System.Data.Entity.CreateDatabaseIfNotExists<Db>
    {
        protected override void Seed(Db context)
        {
            base.Seed(context);
            //TODO 初始化数据

            context.Users.Add(new User()
            {
                Email = "admin",
                IsAdmin = true,
                EmailAuthenticated = true,
                LoginPassword = "123456".MD5(),
                CreateTime = DateTime.Now
            });

            context.SaveChanges();

            SearchEngine se1 = context.SearchEngines.Add(new SearchEngine
             {
                 Disabled = false,
                 Name = "百度",
                 Provider = "BaiduEngine"
             });

            SearchEngine se2 = context.SearchEngines.Add(new SearchEngine
             {
                 Disabled = false,
                 Name = "谷歌(简体)",
                 Provider = "GoogleCNEngine"
             });

            context.SaveChanges();

            context.SeoSites.Add(new SeoSite()
            {
                Name = "www.abc.com",
                Deleted = false,
                CreateTime = DateTime.Now,
                Ftp = "ftp://abc.com",
                FtpPort = "21",
                FtpUserName = "abc",
                FtpPassword = "123456",
                Trades = "sdf",
                SiteUrl = "www.abc.com",
                UserID = 1
            });


            context.SaveChanges();

            context.SeoKeywords.Add(new SeoKeyword
            {
                CreateTime = DateTime.Now,
                IsAuthenticated = false,
                KeywordName = "word1",
                Price = 20,
                SeoSiteID = 1,
                SearchEngines = new List<SearchEngine> { se1, se2 }
            });

            

            context.SeoKeywords.Add(new SeoKeyword
            {
                CreateTime = DateTime.Now,
                IsAuthenticated = false,
                KeywordName = "word2",
                Price = 30,
                SeoSiteID = 1,
                SearchEngines = new List<SearchEngine> { se1 }
            });

            context.SaveChanges();
        }
    }
}
